﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using DotNetNuke.Entities.Modules;
using DotNetNuke.Services.Exceptions;

namespace DotNetNuke.Modules.Razor.Forum
{
    public partial class Settings : ModuleSettingsBase
    {

        public override void LoadSettings()
        {
            try
            {
                if (Page.IsPostBack == false)
                {
                    if (ModuleSettings["TabID"] != null)
                    {
                        txtbxTabID.Text = (string)ModuleSettings["TabID"];
                    }

                    if (ModuleSettings["ModuleID"] != null)
                    {
                        txtbxModuleID.Text = (string)ModuleSettings["ModuleID"];
                    }

                    if (ModuleSettings["PageSize"] != null)
                    {
                        txtbxCount.Text = (string)ModuleSettings["PageSize"];
                    }
                }
            }
            catch (Exception exc) //Module failed to load
            {
                Exceptions.ProcessModuleLoadException(this, exc);
            }
        }

        public override void UpdateSettings()
        {
            try
            {
                ModuleController objModules = new ModuleController();
                objModules.UpdateModuleSetting(ModuleId, "TabID", txtbxTabID.Text);
                objModules.UpdateModuleSetting(ModuleId, "ModuleID", txtbxModuleID.Text);
                objModules.UpdateModuleSetting(ModuleId, "PageSize", txtbxCount.Text);

                ModuleController.SynchronizeModule(ModuleId);
            }
            catch (Exception exc) //Module failed to load
            {
                Exceptions.ProcessModuleLoadException(this, exc);
            }
        }
    }
}